<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%@ include file="../taglibs.jsp"%>
<%@taglib prefix="staticResource" tagdir="/WEB-INF/tags/header"%>
<staticResource:staticResource></staticResource:staticResource>
<style type="text/css">
<
title
>
<
fmt
:message
 
key
="application
.title
"/
>
</
title
>
</style>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=39c84239558daf36d465bbcb444fbfd9 "></script>
<style type="text/css">
b {
	color: #666;
}

body, html, #address {
	width: 100%;
	height: 100%;
	overflow: hidden;
	margin: 0;
	float: right;
}
</style>

</head>
<body class="easyui-layout">

	<!-- title链接 -->
	<div data-options="region:'north',border:false" style="height: 32px; background: #FFF; padding: 0px">
		<div class="navBox">
			<table height="100%">
				<tr>
					<td>
						<img src="${ctx }/static/images/home/icon0.png" />
					</td>
					<td>${set.sysName}&gt;&gt;系统管理&gt;&gt; 系统设置</td>
				</tr>
			</table>
		</div>
	</div>

	<!-- content -->
	<div data-options="region:'center',title:''" style="overflow-x: hidden; padding: 5px;">
		<div id="toolbar" style="padding: 3px">
			<div>
				<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="add()">添加</a>
				<a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="edit()">修改</a>
				<!-- <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="deleteAll()">删除</a>
				 <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="setAddress()">设置地址</a> -->
				<a href="#" class="easyui-linkbutton" iconCls="icon-redo" plain="true" onclick="restSys()">系统重置</a>
			</div>
		</div>
		<div style="float: left; width: 100%; height: auto; padding: 2px">
			<div style="float: left; width: 100%; margin-top: 5px;">
				<table id="dg">
				</table>
			</div>
		</div>
	</div>

	<div id="dlg" class="easyui-dialog" closed="true" data-options="modal:true" style="width: 450px;">

		<!-- form -->
		<form id="fm" method="post" enctype="multipart/form-data">
			<input name="sysId" type="hidden">
			<table id="table3" width="99%" height="330px">
				<tr>
					<td>系统名称</td>
					<td>
						<input style="width: 300px" class="easyui-textbox" type="text" name="sysName" />
					</td>
				</tr>
				<tr>
					<td>单位名称</td>
					<td>
						<input style="width: 300px" class="easyui-textbox" type="text" name="company" />
					</td>
				</tr>
				<tr>
					<td>地址</td>
					<td>
						<input style="width: 300px" class="easyui-textbox" type="text" name="address" />
					</td>
				</tr>
				<tr>
					<td>电话</td>
					<td>
						<input style="width: 300px" class="easyui-textbox" type="text" name="tel" />
					</td>
				</tr>
				<tr>
					<td>联系人</td>
					<td>
						<input style="width: 300px" class="easyui-textbox" type="text" name="charger" />
					</td>
				</tr>
				<tr>
					<td>单位简介</td>
					<td>
						<input style="width: 300px; height: 60px" class="easyui-textbox" data-options="multiline:true" name="brief" />
					</td>
				</tr>
				<tr>
					<td>系统描述</td>
					<td>
						<input style="width: 300px; height: 60px" class="easyui-textbox" data-options="multiline:true" name="remark" />
					</td>
				</tr>
				<tr>
					<td>企业LOGO</td>
					<td>
						<input name="file" class="easyui-filebox" buttonText="选择图片">
					</td>
				</tr>

				<tr align="center">
					<td height="30" colspan="2" align="center">
						<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="save()">确定</a>
						&nbsp;&nbsp;
						<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>
					</td>
				</tr>
			</table>
		</form>
	</div>

	<!-- 地址设置 -->
	<div id="address"></div>

</body>

<!-- datagrid -->
<script type="text/javascript">
	$(function(){
		// 获取浏览器窗口 
		var windowScreen = document.documentElement;
		var h = windowScreen.clientHeight;
		
		$("#dg").datagrid({
			url : '${ctx}/system/set/list',
			height : (h - 50),
			nowrap : true,
			autoRowHeight : true,
			striped : false,
			collapsible : false,
			fitColumns : true,
			singleSelect:true,
			remoteSort : false,
			pagination : true,//显示分页 
			rownumbers:true,
			idField : 'sysId',
			toolbar : $("#toolbar"),
			columns : [ [ 
				  {field : 'sysId',title : 'ID',checkbox : true},
	              {field : 'sysName',title : '系统名称',width : 10,align : 'left'},
	              {field : 'company',title : '单位名称',width : 10,align : 'center'},
	              {field : 'address',title : '地址',width : 10,align : 'center'}, 
				  {field : 'tel',title : '电话',width : 10,align : 'center'},
				  {field : 'charger',title : '联系人',width : 10,align : 'center'},
				  {field : 'brief',title : '单位简介',width : 10,align : 'center'},
				  {field : 'remark',title : '系统描述',width : 10,align : 'center'},
				  {field : 'picture',title : '系统LOGO',width : 10,align : 'center',formatter:function(value, row, index) {
						var str='<a href="#" onclick="showImg(\''+row.dmtName+'\',\''+value+'\')">点击查看</>';
						return str;						
			  	  }}
				] ]
			});
		});
	var url;
	//add
	function add(){
		$('#dlg').dialog('open').dialog('setTitle', '添加企业信息');
		$('#fm').form('clear');
		url = '${ctx}/system/set/save';
	}
	
	//edit
	function edit(){
		var rows = $('#dg').datagrid('getSelections');
		if (rows.length != 1) {
			$.messager.alert('提示', '请选择一条记录', 'info');
		} else {
			$('#dlg').dialog('open').dialog('setTitle', '修改企业信息');
			$('#fm').form('load', rows[0]);
			url = '${ctx}/system/set/update';
		}
	}
	
	function save() {
		$('#fm').form('submit', {
			url : url,
			onSubmit : function() {
				return $(this).form('validate');
			},
			success : function(response) {
				response = eval('(' + response + ')');
				console.log(response);
				$.messager.show({
					title : response.title,
					msg : response.msg,
					timeout : response.timeout,
					showType : response.showType
				});
				$('#dlg').dialog('close');
				$('#dg').datagrid('reload');
			}
		});
	}
	
	function deleteAll(){
	var rows = $('#dg').datagrid('getSelections');
	if(null==rows || rows.length<1){
		$.messager.alert('提示','请至少选择一条记录','info');
	}else{
		$.messager.confirm('提示','确认删除选中的记录吗?',function(r){
			//获取datagrid选中行
			if (r){
				$.post('${ctx}/system/set/deleteAll?setId='+rows[0].setId,function(response){
					$.messager.show({
						title:response.title,
						msg:response.msg,
						timeout:response.timeout,
						showType:response.showType
					});
					$('#dlg').dialog('close');
					$('#dg').datagrid('reload');
				},'json');
			}
		});
	}
	}
	
	function restSys(){
		$.ajax({  
            url:'${ctx}/system/set/clearSys',
             dataType:'json',  
             success:function(data){  
            	 $.messager.confirm('提示', '绑定成功后需要重新登录,确认重新登录吗?', function(r) {
         			if (r) {
         				 var url = '${ctx}/logout';
         				 window.parent.location = url;
         			}
         		});
             }  
        });
	}
	
</script>
</html>